# frozen_string_literal: true

ActiveAdmin.register VariableType do
  menu parent: ['Type System'], priority: 1

  permit_params do
    permitted = %i[name klass]
    permitted
  end

  filter :name, filters: %i[equals contains]
  filter :status, as: :select, collection: proc { VariableType::Status.values }
  filter :klass, filters: %i[equals]

  index do
    selectable_column
    id_column
    column 'Name', :name
    column 'Class', :klass
    column 'Status', 'status'

    actions defaults: false do |type|
      item 'View', admin_variable_type_path(type)
    end
  end

  form do |f|
    f.inputs do
      f.input :name
      # f.input :klass
    end
    f.actions
  end

  show do
    attributes_table do
      row :name
      row :klass
      row :status
      row :created_at
      row :updated_at
    end

    panel 'Supported methods' do
      type_methods = variable_type.type_methods.page(params[:page]).per(10)
      paginated_collection(type_methods, download_links: false) do
        table_for type_methods do
          column :name
          column :parameters
          column :description
          column :created_at
          column :updated_at

          column 'Actions' do |type_method|
            span class: 'inline-span' do
              link_to 'View', admin_type_method_path(type_method)
            end
          end
        end
      end
    end
  end
end
